<template>
    <h2>我是ABout组件的内容</h2>
</template>

<script>
export default {
    name:'About',
    //  mounted() {
    //   console.log('About组件挂载了',this)
    //   window.aboutRoute = this.$route
    //   window.aboutRouter = this.$router
    // },
    // beforeDestroy() {
    //     console.log('About组件被销毁了')
    // }
    activated(){
        console.log('About组件：actived方法......')
    },
    deactivated(){
        console.log('About组件：deactived方法......')
    }, 
    //通过路由规则，进入该组件时被调用，需要放行才能显示组件内容
    beforeRouteEnter (to, from, next) {
        console.log('About组件内路由守卫进入：beforeRouteEnter......')
        if(to.meta.isAuth){ // 为true才校验权限，home组件没加为undefined也为false
            //简单判断localStorage中的name是不是tom，是就放行，需要手动添加到localStorage
            if(localStorage.getItem('name') === 'tom'){
                next()
            }else{
                alert('名字不对，无权限查看！')
            }
        }else{
            next()
        }
    },
    //通过路由规则，离开该组件时被调用，需要放行才能离开组件
    beforeRouteLeave (to, from, next) {
        console.log('About组件内路由守卫离开：beforeRouteLeave......')
        next()
    }
}
</script>

<style>

</style>